<template>
  <div>
    <button @click="addNum">添加数字</button>
    <button @click="removeNum">删除数字</button>
    <button @click="shuffleNum">数字洗牌</button>

    <transition-group tag="p" name="pengfan">
      <span v-for="item in numbers" :key="item" class="item">{{ item }}</span>
    </transition-group>
  </div>
</template>

<script>
import _ from "lodash";
export default {
  data() {
    return {
      numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
      numberCounter: 10,
    };
  },
  methods: {
    addNum() {
      //   this.numbers.push(this.numberCounter++);
      this.numbers.splice(this.randomIndex(), 0, this.numberCounter++);
    },
    removeNum() {
      this.numbers.splice(this.randomIndex(), 1);
    },
    randomIndex() {
      return Math.floor(Math.random() * this.numbers.length);
    },
    shuffleNum() {
      this.numbers = _.shuffle(this.numbers);
    },
  },
};
</script>

<style scoped>
.item {
  display: inline-block;
  margin-right: 10px;
}
.pengfan-enter-from,
.pengfan-leave-to {
  opacity: 0;
  transform: translateY(30px);
}

.pengfan-enter-active,
.pengfan-leave-active {
  transition: all 1s ease;
}

.pengfan-leave-active {
  position: absolute;
}
.pengfan-move {
  transition: transform 1s ease;
}
</style>